package com.sskj.gcc.ui.fragment;


import android.text.TextUtils;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.sskj.common.rxbus2.BusData;
import com.sskj.common.rxbus2.RxBus;
import com.sskj.common.rxbus2.Subscribe;
import com.sskj.common.rxbus2.ThreadMode;
import com.sskj.gcc.R;
import com.sskj.gcc.bean.SummaryBean;
import com.sskj.gcc.bean.rxbus.MarketCoinBean;
import com.sskj.gcc.presenter.SummaryFragmentPresenter;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseFragment;
import com.sskj.lib.bean.CoinBean;

import butterknife.BindView;

@Route(path = RConfig.APP_FRAGMENT_SUMMARY)
public class SummaryFragment extends BaseFragment<SummaryFragmentPresenter> {
    @Autowired
    String code;
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.tvFirst)
    TextView tvFirst;
    @BindView(R.id.tvSecond)
    TextView tvSecond;
    @BindView(R.id.tvThird)
    TextView tvThird;
    @BindView(R.id.tvFour)
    TextView tvFour;
    @BindView(R.id.tvContent)
    TextView tvContent;
    @BindView(R.id.tvFive)
    TextView tvFive;

    @Override
    protected int getLayoutId() {
        return R.layout.app_fragment_summary;
    }

    @Override
    public SummaryFragmentPresenter getPresenter() {
        return new SummaryFragmentPresenter();
    }

    @Override
    public void initView() {
        RxBus.getDefault().register(this);
        ARouter.getInstance().inject(this);
    }

    @Override
    public void initData() {
        mPresenter.getSummary(code);
    }

    /**
     * K线点击抽屉切换code
     */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void changeCoin(BusData<CoinBean> busData) {
        if ("KLevel".equals(busData.getId())) {
            code = busData.getData().getCode();
            mPresenter.getSummary(code);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void changeCoin(MarketCoinBean marketCoinBean) {
        if (mPresenter == null) {
            return;
        }
        mPresenter.getSummary(marketCoinBean.getCode());
    }

    public void updateUI(SummaryBean data) {
        if (data != null) {
            tvTitle.setText(data.getPname());
            tvFirst.setText(data.getFxtime());
            //发行总量
            if (!TextUtils.isEmpty(data.getFxnum()))
            tvSecond.setText(data.getFxnum().contains("万") ? data.getFxnum() : data.getFxnum() + getString(R.string.strSummaryFragment201));
            tvThird.setText(data.getFxbook());
            tvFour.setText(data.getFxweb());
            tvContent.setText(data.getMemo());
            //流通总量
            if (!TextUtils.isEmpty(data.getLtnum()))
            tvFive.setText(data.getLtnum().contains("万") ? data.getLtnum() : data.getLtnum() + getString(R.string.strSummaryFragment201));
        }

    }


}
